package com.dts.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.annotation.WebInitParam;

import java.io.IOException;

@WebFilter(filterName = "anFilter",urlPatterns = "/*",initParams = {@WebInitParam(name="userName",value = "admin")},dispatcherTypes = DispatcherType.REQUEST)
public class AnFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("初始化过滤器");
        System.out.println(filterConfig.getInitParameter("userName"));
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("执行url，进入此方法");
        chain.doFilter(request,response);//进入下一个过滤器或url
    }
    @Override
    public void destroy() {
        System.out.println("关闭服务器时执行");
    }
}

